package XishiBackend.services.android;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import XishiBackend.models.entity.Admin;
import XishiBackend.models.repository.AdminRepository;

@Service
@Transactional
public class AndroidAdminService {
    @Autowired
    private AdminRepository aR;
    
    public Admin findOne(long adminId) {
        return aR.findOne(adminId);
    }
    
    public Admin findByLoginName(String loginName) {
        return aR.findByLoginName(loginName);
    }
    
    public boolean save(Admin a) {
        Admin ra = aR.save(a);
        if(!ra.getLoginName().equals(a.getLoginName())) {
            return false;
        }
        if(!ra.getPersonName().equals(a.getPersonName())) {
            return false;
        }
        if(!ra.getPassword().equals(a.getPassword())) {
            return false;
        }
        if(ra.getRestaurantId() != a.getRestaurantId()) {
            return false;
        }
        if(!ra.getLastLoginTime().equals(a.getLastLoginTime())) {
            return false;
        }
        if(!ra.getDeviceToken().equals(a.getDeviceToken())){
            return false;
        }
        if(ra.getLevel() != a.getLevel()) {
            return false;
        }
        if(!ra.getToken().equals(a.getToken())) {
            return false;
        }
        return true;
    }
}
